<?php
    /**
    * @author trungdt 
    * @since Nov 3, 2011
    * 
    * Change logs
    * 
    */
    if (!defined("EXPONENT")) exit("");

    $item = null;
    if (isset($_POST['id'])) {
        $item = $db->selectObject("calendar","id=".intval($_POST['id']));
        $loc = unserialize($item->location_data);
    }

    if (($item == null && exponent_permissions_check("post",$loc)) ||
    ($item != null && exponent_permissions_check("edit",$loc))
    ) {
        $item = calendar::update($_POST,$item, $loc);
        $item->location_data = serialize($loc);

        if (isset($_POST['category'])) 
            $item->category_id = $_POST['category'];
        else $item->category_id = 0;

        if (isset($item->id))
            $db->updateObject($item,"calendar");
        else
            $db->insertObject($item,"calendar");

        exponent_flow_redirect();
    } else {
        echo SITE_403_HTML;
    }

?>
